package com.monitor.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.monitor.dao.ContactDao;
import com.monitor.po.Contact;
import com.monitor.service.ContactService;
import com.monitor.util.CommenUtil;
import com.monitor.util.Pager;

public class ContactServiceImpl implements ContactService {
	private ContactDao contactDao;

	@Override
	public Pager<Contact> getContactListByUid(long uid, int pageSize, int currentPage) throws Exception {
		return contactDao.getContactByUid(uid, pageSize, currentPage);
	}

	@Override
	public boolean deleteContactById(long uid, String cid) throws Exception {
		return contactDao.deleteContact(uid, cid) > 0;
	}

	@Override
	public boolean deleteContactByPhones(long uid, String phoneStr) throws Exception {
		if (CommenUtil.isEmpty(phoneStr))
			return false;
		String[] phones = phoneStr.split(",");
		return contactDao.deleteContact(uid, phones) > 0;
	}

	@Override
	public void addContact(long uid, String phone, String name) throws Exception {
		Contact contact = new Contact();
		contact.setName(name);
		contact.setOwnerUid(uid);
		contact.setPhone(phone);
		List<Contact> contacts = new ArrayList<Contact>();
		contacts.add(contact);
		contactDao.addContact(uid, contacts);
	}

	public ContactDao getContactDao() {
		return contactDao;
	}

	public void setContactDao(ContactDao contactDao) {
		this.contactDao = contactDao;
	}

}
